package com.example.demo;

import com.example.demo.Component.UserComponent;
import com.example.demo.Configuration.UserConfiguration;
import com.example.demo.Controller.UserController;
import com.example.demo.Model.User;
import com.example.demo.Repository.UserRepository;
import com.example.demo.Service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        //获取Spring上下文对象
        ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
        //从Spring上下文中获取对象
//        UserController userController = context.getBean(UserController.class);
//        //使用对象
//        userController.sayHi();
//
//        UserService userService = context.getBean(UserService.class);
//        userService.sayHi();
//
//        UserRepository userRepository = context.getBean(UserRepository.class);
//        userRepository.sayHi();
//
//        UserComponent userComponent = context.getBean(UserComponent.class);
//        userComponent.sayHi();
//
//        UserConfiguration userConfiguration = context.getBean(UserConfiguration.class);
//        userConfiguration.sayHi();
//        User user = context.getBean(User.class);
//        System.out.println(user);
//        User user1 = (User) context.getBean("user1");
//        User user2 = (User) context.getBean("user2");
//        System.out.println(user1);
//        System.out.println(user2);
        UserController userController = context.getBean(UserController.class);
        userController.sayHi();
    }
}
